package com.cskaoyan.market.util;

import com.cskaoyan.market.exception.ValidationException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2024/7/2 9:49
 * @Version 1.0
 */
public class ValidationUtils {

    public static void validate2(BindingResult bindingResult) {
        boolean errors = bindingResult.hasErrors();
        if(errors){
            FieldError fieldError = bindingResult.getFieldError();
            String defaultMessage = fieldError.getDefaultMessage();
            String field = fieldError.getField();
            throw new ValidationException(401, field + " " + defaultMessage);
        }
    }
}
